from pydantic import BaseModel
from typing import Optional, Union, Callable,Any
from fastapi import HTTPException

from starlette.responses import JSONResponse


class ResponseModel(BaseModel):
    code: int
    message: str
    data: Optional[Union[dict, list, str, int, float, bool,Any]] = None

    def __str__(self):
        return f"ResponseModel(code={self.code}, message={self.message}, data={self.data})"

    def __repr__(self):
        return self.__str__()

    @classmethod
    def success(cls, data=None):
        return cls(code=200, message="success", data=data).model_dump()

    @classmethod
    def error(cls, code=500, message="error"):
        return cls(code=code, message=message, data=None).model_dump()